import request from '@/utils/request';
/**
 * 卡券增加
 * @param params 查询条件
 */

export async function cardRollInsert(data) {
  const res = await request.post('/massage/cardRoll', data);
  if (res.data.code === 200) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 分类列表查询
 * @param params 查询条件
 */

export async function cardRollList(params) {
  const res = await request.get('/massage/cardRoll/page', {
    params
  });
  if (res.data.code === 200) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 卡券修改修改
 * @param params 查询条件
 */
export async function cardRollModify(data) {
  const res = await request.put('/massage/cardRoll', data);
  console.log(res);
  if (res.data.code === 200) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

// 更新优惠卷状态

export async function updateDiscountCouponType() {
  const res = await request.get('/massage/cardRoll/updateDiscountCouponType');
  console.log(res);
  if (res.data.code === 200) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 卡券详情查询
 * @param params 查询条件
 */

export async function cardRollDetail(params) {
  const res = await request.get('/massage/cardRoll/get/', { params });

  if (res.data.code === 200) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 卡券删除
 * @param params 查询条件
 */

export async function cardRollDelete(id) {
  const res = await request.delete('/massage/cardRoll/' + id);
  console.log(res);
  if (res.data.code === 200) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 批量删除卡券
 * @param params 查询条件
 */

export async function cardRollBatchDelete(data) {
  const res = await request.delete('/massage/cardRoll/batch', {
    data
  });
  console.log(res);
  if (res.data.code === 200) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
